// Example File Command script showing built-in functions for buffer manipulation,
// including length, CRC, and ECC functions.

# FILE "../DSIDataTypes.txt"

# BUF payload
1 2 3 4 5 6

// show assertion function; use length function in boolean expression and notification
# ASSERT (length(payload) == 6) "Unexpected payload length: " length(payload)

// create generic long write packet (pkt)
# BUF pkt
DT_GENERIC_LONG_WRITE -4 -1: # STREAM payload: -2

// show hex function as argument to MSGBOX
// show crc function using entire payload buffer as argument
# MSGBOX "CRC for payload buffer is" hex(crc(payload))

// ECC calculations 
# ASSERT (pkt[3] == ECC(pkt)) "Computed ECC (" hex(ECC(pkt)) ") does not match ECC in header (" hex(pkt[3]) ")"
# MSGBOX "ECC for pkt is" hex(ECC(pkt))

// use CRC function and get last two bytes of pkt (payload CRC)
# payloadCRC = crc(payload)
# pktCRC = (pkt[length(pkt)-1] << 8) | pkt[length(pkt)-2]
# ASSERT (pktCRC == payloadCRC) "Computed CRC (" hex(payloadCRC) ") does not match CRC in packet (" hex(pktCRC) ")"
# MSGBOX "CRC for pkt payload is" hex(pktCRC)
# MSGBOX "CRC for pkt[4] to pkt[9] is" hex(crc(pkt,4,length(payload)))

// create two packet burst (pkt2) by streaming pkt twice
# BUF pkt2
# STREAM pkt
# STREAM pkt

// show optional second argument (start offset) to ECC function
# MSGBOX "ECC for second pkt in pkt2 is" hex(ECC(pkt2,length(pkt)))

// modify last byte in pkt2
# pkt2[length(pkt2)-1] = pkt2[length(pkt2)-1] ^ 10h
# MSGBOX pkt2

// get pkt2 length as variable and print out last byte in pkt2 as hex value using hex function
# len = length(pkt2)
# MSGBOX "Pkt2 burst length is" len ". Last byte in pkt2 is" hex(pkt2[len - 1])

